package com.yunc.modules.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunc.modules.sys.entity.SysUserRole;
import com.yunc.modules.sys.mapper.SysUserRoleMapper;
import com.yunc.modules.sys.service.ISysUserRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 系统角色
 *
 * @author congcong tao
 * @date 2018/5/14 16:17
 */
@Service("sysUserRoleService")
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {

    @Autowired
    private SysUserRoleMapper sysUserRoleMapper;

    @Override
    public boolean insertList(Long userId, String roleIds) {
        if (StringUtils.isNotEmpty(roleIds)) {
            String[] roleIdArr = roleIds.split(",");
            if (roleIdArr != null && roleIdArr.length > 0) {
                for (String roleId : roleIdArr) {
                    SysUserRole userRole = new SysUserRole();
                    userRole.setUserId(userId);
                    userRole.setRoleId(Long.valueOf(roleId));
                    boolean flag = this.save(userRole);
                    if (!flag) {
                        return flag;
                    }
                }
                return true;
            }
        }
        return false;
    }
}
